<template>
  <el-table :data="tableData" :height="tableHeight" :show-header="false" border class="cursor" highlight-current-row
            @row-click="getMessage">
    <el-table-column label="知识名称"
                     min-width="180"
                     prop="name">
      <template slot-scope="scope">
        <span v-html="scope.row.name"></span>
      </template>
    </el-table-column>
  </el-table>
</template>

<script>
export default {
  name: "MessageTable",
  props: {
    system: String,
    scheme: String,
    edit: String,
    audit: String,
    manage: String
  },
  data() {
    return {
      tableData: [],
      tableHeight: '',
      schemeEditor: '0001AA100000000L9GZG',//策划编辑
      editor: '1446721663839256577',//编辑
      auditor: '1455779077465059330',//编审
    }
  }, methods: {

    getMessage(row) {
      if (this.audit === '3' && this.scheme === '2' || this.manage === '4') {
        if (this.system === 'newTask') {
          if (row.markStatus === '1') {
            this.$router.push({
              path: '/taskEditManage',
              query: {
                taskItemId: row.id,
                taskItemType: 'newTask',
                taskItemStatus: "",
                knowledgeLibId: row.knowledgeLibId
              }
          });} else {
            this.$router.push({
              path: '/myAudit',
              query: {
                taskItemId: row.id,
                taskItemType: 'newTask',
                knowledgeLibId: row.knowledgeLibId
              }
            });
          }
        } else if (this.system === 'rejectTask') {
          if (row.status === 0 || row.status === 3) {
            this.$router.push({
              path: '/taskEditManage',
              query: {
                taskItemId: row.taskId,
                taskItemType: 'rejectTask',
                taskItemName: row.name,
                taskItemStatus: row.status,
                knowledgeLibId: row.knowledgeLibId
              }
            });
          } else {
            this.$router.push({
              path: '/myAudit',
              query: {
                taskItemId: row.taskId,
                taskItemType: 'rejectTask',
                taskItemName: row.name,
                taskItemStatus: row.status,
                knowledgeLibId: row.knowledgeLibId

              }
            });
          }

        } else {
          if (row.status === 0 || row.status === 3) {
            this.$router.push({
              path: '/taskEditManage',
              query: {
                taskItemId: row.taskId,
                taskItemName: row.name,
                taskItemType: 'pressTask',
                taskItemStatus: "",
                knowledgeLibId: row.knowledgeLibId
              }
            });
          } else {
            this.$router.push({
              path: '/myAudit',
              query: {
                taskItemId: row.taskId,
                taskItemName: row.name,
                taskItemType: 'pressTask',
                taskItemStatus: row.status,
                knowledgeLibId: row.knowledgeLibId
              }
            });
          }

        }
      } else if (this.edit === '1' || this.scheme === '2') {
        if (this.system === 'newTask') {
          this.$router.push({
            path: '/taskEditManage',
            query: {
              taskItemId: row.id,
              taskItemType: 'newTask',
              taskItemStatus: "",
              knowledgeLibId: row.knowledgeLibId
            }
          });
        } else if (this.system === 'rejectTask') {
          this.$router.push({
            path: '/taskEditManage',
            query: {
              taskItemId: row.taskId,
              taskItemType: 'rejectTask',
              taskItemName: row.name,
              taskItemStatus: row.status,
              knowledgeLibId: row.knowledgeLibId
            }
          });
        } else {
          this.$router.push({
            path: '/taskEditManage',
            query: {
              taskItemId: row.taskId,
              taskItemName: row.name,
              taskItemType: 'pressTask',
              taskItemStatus: "",
              knowledgeLibId: row.knowledgeLibId
            }
          });
        }
      } else if (this.audit === '3') {
        if (this.system === 'newTask') {
          if (row.markStatus === '1') {
            this.$router.push({
              path: '/taskEditManage',
              query: {
                taskItemId: row.id,
                taskItemType: 'newTask',
                taskItemStatus: "",
                knowledgeLibId: row.knowledgeLibId
              }
          });} else {
            this.$router.push({
              path: '/myAudit',
              query: {
                taskItemId: row.id,
                taskItemType: 'newTask',
                knowledgeLibId: row.knowledgeLibId
              }
            });
          }
        } else if (this.system === 'rejectTask') {
          if (row.status === 0 || row.status === 3) {
            this.$router.push({
              path: '/taskEditManage',
              query: {
                taskItemId: row.taskId,
                taskItemType: 'rejectTask',
                taskItemName: row.name,
                taskItemStatus: row.status,
                knowledgeLibId: row.knowledgeLibId
              }
            });
          } else {
            this.$router.push({
              path: '/myAudit',
              query: {
                taskItemId: row.taskId,
                taskItemType: 'rejectTask',
                taskItemName: row.name,
                taskItemStatus: row.status,
                knowledgeLibId: row.knowledgeLibId
              }
            });
          }
        } else {
          if (row.status === 0 || row.status === 3) {
            this.$router.push({
              path: '/taskEditManage',
              query: {
                taskItemId: row.taskId,
                taskItemName: row.name,
                taskItemType: 'pressTask',
                taskItemStatus: "",
                knowledgeLibId: row.knowledgeLibId
              }
            });
          } else {
            this.$router.push({
              path: '/myAudit',
              query: {
                taskItemId: row.taskId,
                taskItemName: row.name,
                taskItemType: 'pressTask',
                taskItemStatus: row.status,
                knowledgeLibId: row.knowledgeLibId
              }
            });
          }
        }
      }
    },
    getTableData() {
      this.axios.get('/pmph/action/work/selectEditMessageTable', {
        params: {
          system: this.system
        }
      }).then((response) => {
        this.tableData = response.data

      })
    },
    getEditAndSchemeTableData() {
      this.axios.get('/pmph/action/work/selectEditAndSchemeTable', {
        params: {
          system: this.system
        }
      }).then((response) => {
        this.tableData = response.data

      })
    },
    getAuditTableData() {
      this.axios.get('/pmph/action/work/selectAuditTableData', {
        params: {
          system: this.system
        }
      }).then((response) => {
        this.tableData = response.data

      })
    }
  },
  created() {
    this.tableHeight = CONST.WORKSPACE_HEIGHT - 390;
    this.axios.get('/pmph/action/work/selectRoleName', {}).then((response) => {
      this.roleTable = response.data
      let scheme = ''
      let edit = ''
      let auditTable = ''
      for (let i = 0; i < this.roleTable.length; i++) {
        if (this.roleTable[i].id === this.editor) {
          edit = '1'
        } else if (this.roleTable[i].id === this.schemeEditor) {
          scheme = '2'
        } else if (this.roleTable[i].id === this.auditor) {
          auditTable = '3'
        }
      }
      if (auditTable === '3' && scheme === '2') {
        this.getEditAndSchemeTableData()
      } else if (edit === '1' || scheme === '2') {
        this.getTableData()
      } else if (auditTable === '3') {
        this.getAuditTableData()
      } else if (auditTable === '3' && edit === '1') {
        this.getAuditTableData()
      } else {
        this.getEditAndSchemeTableData()

      }
    })
  }
}
</script>

<style scoped>
.cursor {
  cursor: pointer;
}
</style>
